<?php
require 'isok.php';
    require 'database.php';
      if (!empty($_POST)){
        //$_POST表单提交数据
        //文章id
         $id= $_POST[ 'id'];
         //删除id
         unset($_POST['id']);
         //调用update 执行操作
        $res=update('posts', $_POST, $id);
       if ($res['status']==1){
           header('Location:posts.php');
       } else {
           header('Content-Type:text/html; charset=UTF-8');
           echo '修改失败！';
       }
       exit();
     }
    $id=isset($_GET['id'])?$id=$_GET['id']:'';
      $row=find( 'posts',array('id '=>$id));
    $categories = find('categories');
  
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>阿里百秀登录管理</title>
  <link rel="stylesheet" href="../assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="../assets/vendors/font-awesome/css/font-awesome.css">
  <link rel="stylesheet" href="../assets/vendors/ueditor/themes/default/css/umeditor.min.css">
  <link rel="stylesheet" href="../assets/vendors/nprogress/nprogress.css">
  <link rel="stylesheet" href="../assets/css/admin.css">
  <script src="../assets/vendors/nprogress/nprogress.js"></script>
</head>
<body>
  <script>NProgress.start()</script>

  <div class="main">
    <nav class="navbar">
      <button class="btn btn-default navbar-btn fa fa-bars"></button>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="profile.php"><i class="fa fa-user"></i>个人中心</a></li>
        <li><a href="login.php"><i class="fa fa-sign-out"></i>退出</a></li>
      </ul>
    </nav>
    <div class="container-fluid">
      <div class="page-title" >
        <h1>修改文章</h1>
      </div>
      <!-- 有错误信息时展示 -->
      <!-- <div class="alert alert-danger">
        <strong>错误！</strong>发生XXX错误
      </div> -->
      <form class="row" action="post-edit.php" enctype="multipart/form-data" method="post">
          <input name="id" type="hidden" value="<?php echo $row[0]['id']; ?>"/>
          <div class="col-md-9">
          <div class="form-group">
            <label for="title">标题</label>
            <input id="title" class="form-control input-lg" name="title" type="text" value="<?php echo $row[0]['title']; ?>"  placeholder="文章标题">
          </div>
          <div class="form-group">
            <label for="content">标题</label>
            <textarea id="content" class="form-control input-lg" name="content" cols="30" rows="10" placeholder="内容"><?php echo $row[0]['content']; ?></textarea>
          </div>
        </div>
        <div class="col-md-3">
          <div class="form-group">
            <label for="slug">别名</label>
            <input id="slug" class="form-control" value="<?php echo $row[0]['slug']; ?>" name="slug" type="text" placeholder="slug">
            <p class="help-block">https://zce.me/post/<strong>slug</strong></p>
          </div>
          <div class="form-group">
            <label for="feature">特色图像</label>
            <!-- show when image chose -->
            <?php if($row[0]['feature']){ ?>
            <img class="help-block thumbnail" src="<?php echo" /php2017404107/baixiu/". $row[0]['feature']; ?>" >
            <?php }?>
            <input id="feature" value="<?php echo $row[0]['feature']; ?>" class="form-control" name="feature" type="file">
          </div>
          <div class="form-group">
            <label for="category">所属分类</label>
            <select id="category" class="form-control" name="category_id">
               <?php
               foreach ($categories as $key=>$val) 
               {
                   ?>
                <option <?php if ($row[0]['category_id'] ==$val['id']) echo 'selected'; ?> value="<?php echo $val['id']; ?>"><?php echo $val['name']; ?></option>  
                <?php           
               }
               ?>
            </select>
          </div>
          <div class="form-group">
            <label for="created">发布时间</label>
            <input id="created" value="<?php echo $row[0]['created']; ?>" class="form-control" name="created" type="text">
          </div>
          <div class="form-group">
            <label for="status">状态</label>
            <select id="status" class="form-control" name="status">
               <option value="drafted" <?php if ($row[0]['status'] == 'drafted') echo 'selected'; ?>>草稿</option>
              <option value="published" <?php if ($row[0]['status'] == 'published') echo 'selected'; ?>>已发布</option>
            </select>
          </div>
          <div class="form-group">
            <button class="btn btn-primary" type="submit">修改</button>
          </div>
        </div>
      </form>
    </div>
  </div>
<?php include 'aside.php';?>
  <script src="../assets/vendors/jquery/jquery.js"></script>
  <script src="../assets/vendors/bootstrap/js/bootstrap.js"></script>
  <script src="../assets/vendors/ueditor/umeditor.config.js"></script>
  <script src="../assets/vendors/ueditor/umeditor.min.js"></script>
  <script>NProgress.done()</script>
    <script>
     var ue=UM.getEditor('content',{
         initialFrameWidth:'100%',
         initialFrameHeight:320});
  </script>   
</body>
</html>